//
//  UIView+Expand.m
//  GoodEit
//
//  Created by ihope99 on 2017/8/3.
//  Copyright © 2017年 GZX. All rights reserved.
//

#import "UIView+ZXExpand.h"
#import <objc/runtime.h>

@implementation UIView (ZXExpand)
static char touchKey;
-(void)actionTap{
    void (^block)(void) = objc_getAssociatedObject(self, &touchKey);
    if (block) block();
}
-(void)addTapTouch:(TouchBlock)block{
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap)];
    [self addGestureRecognizer:tap];
    objc_setAssociatedObject(self, &touchKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

-(CGFloat)CG_MaxX{
    return CGRectGetMaxX(self.frame);
}
-(CGFloat)CG_MaxY{
    return CGRectGetMaxY(self.frame);
}
-(CGFloat)CG_MinX{
    return CGRectGetMinX(self.frame);
}
-(CGFloat)CG_MinY{
    return CGRectGetMinY(self.frame);
}
-(CGFloat)CG_Width{
    return CGRectGetWidth(self.frame);
}
-(CGFloat)CG_Height{
    return CGRectGetHeight(self.frame);
}
-(CGFloat)CG_CenterY{
    return CGRectGetMidY(self.frame);
}
-(CGFloat)CG_CenterX{
    return CGRectGetMidX(self.frame);
}

+(UITextField *)initWithTextFieldFrame:(CGRect)frame
                                  Text:(NSString *)text
                           placeholder:(NSString *)placeholder
                                  font:(float)font
                          keyboardType:(UIKeyboardType)keyboardType
                             textColor:(UIColor *)textColor
                         textAlignment:(NSTextAlignment)textAlignment
                              delegate:(id)delegate{
    UITextField *_tf = [[UITextField alloc]initWithFrame:frame];
    _tf.text = text;
    _tf.placeholder = placeholder;
    _tf.font = [UIFont systemFontOfSize:font];
    if (keyboardType) {
        _tf.keyboardType = keyboardType;
    }
    if (textAlignment) {
        _tf.textAlignment = textAlignment;
    }
    if (delegate) {
        _tf.delegate = delegate;
    }
    _tf.textColor = textColor;
    return _tf;
}
+(UILabel *)initWithLabelFrame:(CGRect)frame
                          Text:(NSString *)text
                          font:(float)font
                     textColor:(UIColor *)textColor
                 textAlignment:(NSTextAlignment)textAlignment{
    UILabel *_lb = [[UILabel alloc]initWithFrame:frame];
    _lb.text = text;
    _lb.font = [UIFont systemFontOfSize:font];
    if (textAlignment) {
        _lb.textAlignment = textAlignment;
    }
    _lb.textColor = textColor;
    return _lb;
}
+(UIButton *)initWithButtonFrame:(CGRect)frame
                     normalTitle:(NSString *)normalTitle
                normalTitleColor:(UIColor *)normalTitleColor
                   selectedTitle:(NSString *)selectedTitle
              selectedTitleColor:(UIColor *)selectedTitleColor
                            font:(float)font{
    UIButton *_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    _btn.adjustsImageWhenHighlighted = NO;
    _btn.frame = frame;
    [_btn setTitle:normalTitle forState:UIControlStateNormal];
    [_btn setTitleColor:normalTitleColor forState:UIControlStateNormal];
    if (selectedTitle) {
        [_btn setTitle:selectedTitle forState:UIControlStateSelected];
    }
    if (selectedTitleColor) {
        [_btn setTitleColor:selectedTitleColor forState:UIControlStateSelected];
    }
    _btn.titleLabel.font = [UIFont systemFontOfSize:font];
    return _btn;
}
-(void)removeAllSubViews{
    for (UIView *mView in self.subviews) {
        [mView removeFromSuperview];
    }
}
-(void)toRoundWithFloat:(float)height{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = height;
}


@end
